﻿using System;
using System.Web;
namespace System.Web.Hosting
{
    internal class RecyclableArrayHelper
    {
        private const int ARRAY_SIZE = 0x80;
        private const int MAX_FREE_ARRAYS = 0x40;
        private static IntegerArrayAllocator _integerArrayAllocator = new IntegerArrayAllocator(0x80, 0x40);
        private static IntPtrArrayAllocator _intPtrArrayAllocator = new IntPtrArrayAllocator(0x80, 0x40);

        internal static int[] GetIntegerArray(int minimumLength)
        {
            return (minimumLength <= 0x80 ? (int[])_integerArrayAllocator.GetBuffer() : new int[minimumLength]);
        }

        internal static IntPtr[] GetIntPtrArray(int minimumLength)
        {
            return (minimumLength <= 0x80 ? (IntPtr[])_intPtrArrayAllocator.GetBuffer() : new IntPtr[minimumLength]);
        }

        internal static void ReuseIntegerArray(int[] array)
        {
            if ((array != null) && (array.Length == 0x80))
                _integerArrayAllocator.ReuseBuffer(array);
        }

        internal static void ReuseIntPtrArray(IntPtr[] array)
        {
            if ((array != null) && (array.Length == 0x80))
                _intPtrArrayAllocator.ReuseBuffer(array);
        }
    }
}
